package ejb.app;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import portal.entidades.Usuario;
import portal.facade.Facade;

public class Runner {

	public static void main(String[] args) throws NamingException {
		final String appName = "TPO";
		final String moduleName = "tpoPortalEJB";
		final String sessionBeanName = "FacadeBean";
		final String viewClassName = Facade.class.getName();
		Properties jndiProps = new Properties();
		jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
		jndiProps.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
		// username
		jndiProps.put(Context.SECURITY_PRINCIPAL, "test");
		// password
		jndiProps.put(Context.SECURITY_CREDENTIALS, "test123!");
		// This is an important property to set if you want to do EJB
		// invocations via the remote-naming project
		jndiProps.put("jboss.naming.client.ejb.context", true);
		// create a context passing these properties
		Context context = new InitialContext(jndiProps);
		
		// lookup the bean Foo
		Facade facade = (Facade) context.lookup(appName+"/"+moduleName+"/"+sessionBeanName+"!"+viewClassName);
		
		// Login
		Usuario user = facade.login("c", "c");
		if (user==null)
			System.out.println("Usuario o clave incorrecta");
		else
			System.out.println("Successful login!! - Usuario: " + user.getNombre() + " " + user.getApellido());
	}

}
